home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / mindos11.zip / MGETINOD.C < prev    next >
C/C++ Source or Header  |  1991-03-22  |  2KB  |  81 lines

  1. /*  mgetinod.c  -- get requested inode entry */
  2. /*  Copyright 1988,1991 Steven W. Harrold - All rights reserved.*/
  3. /*  $Header: MGETINOD.C_V 1.2 91/03/19 09:57:56 SWH Exp $ */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    <string.h>
  8. #include    "mfs.h"
  9. #include    "dev.h"
  10.  
  11. READ_FILE
  12.  
  13.  
  14. /*==================================================================*/
  15. struct inode *get_inode (ddata, iarea, ip, path)
  16. struct devdata  *ddata ;
  17. struct inode    *iarea ;
  18. struct inode    *ip ;
  19. char            **path ;
  20. {
  21.     struct directory    *darea, *dp ;
  22.     int                 dn, dnz ;
  23.  
  24.     int         i, j, k, n ;
  25.     char        c, *p ;
  26.     char        npath[MAX_PATH+1] ;
  27.     BOOL        found ;
  28.  
  29.  
  30.     dn = ip->i_size / sizeof(struct directory) ;
  31.     dnz = dn * sizeof(struct directory) + BLOCK_SIZE - 1 ;
  32.     dnz /= BLOCK_SIZE ;
  33.     dnz *= BLOCK_SIZE ;
  34.     dnz /= sizeof(struct directory) ;
  35.     darea = calloc (dnz+1, sizeof(struct directory)) ;
  36.     if (!darea)
  37.         exit(3) ;
  38.  
  39.     read_file (darea, ip, ddata) ;
  40.  
  41. /*  Scan the directory for the name of the current path component
  42.  */
  43.     dp = darea ;
  44.     found = FALSE ;
  45.     for (i=0; !found && i<dn; i++, dp++)
  46.         if (strncmp (dp->d_name, *path, NAME_SIZE) == 0)
  47.         {
  48.             found = TRUE ;
  49.             break ;
  50.         }
  51.  
  52.     if (!found)
  53.     {
  54.         ip = NULL ;
  55.         goto quit ;
  56.     }
  57.  
  58.     ip = iarea + dp->d_inum ;
  59.  
  60. /*  Now, for those entries that are themselves directories,
  61.  *  display them recursively.
  62.  */
  63.     path++ ;
  64.     if (!*path)
  65.     {
  66.         goto quit ;
  67.     }
  68.  
  69.     ip = get_inode(ddata, iarea, ip, path) ;
  70.  
  71. /*  Clean up
  72.  */
  73. quit:
  74.     free (darea) ;
  75.     return ip ;
  76.  
  77. } /* get_inode() */
  78.  
  79.  
  80. /*---eof---*/
  81.